package com.springboot.cloud.demos.producer.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.springboot.cloud.demos.entity.po.Album;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface UnitMapper extends BaseMapper<Album> {
    /**
     * 为了区别plus原来的查询select*的字段 ，自定义为dy
     *
     * @param
     * @return 多表关联查询
     */
    @Select("SELECT a.id,a.title,a.view_count as viewCount ,a.subtitle,a.hot_word as hotWord ,a.cover,a.score_high_video  AS scoreHighVideo,a.score_middle_video AS scoreMiddleVideo,a.score_low_video AS scoreLowVideo,a.no_voice_video AS noVoiceVideo ,a.free,a.teacher_id AS teacherId,b.avatar,b.name as teacherName FROM t_unit a LEFT JOIN t_teacher b ON a.teacher_id = b.id where a.level_id=#{id} order by a.created_time asc")
    List<Map<String, Object>> queryByLevel(String id);


    @Select("SELECT a.id,a.title,a.subtitle,a.cover,a.score_high_video AS scoreHighVideo,a.score_middle_video AS scoreMiddleVideo,a.score_low_video AS scoreLowVideo, a.no_voice_video AS noVoiceVideo,a.free,a.teacher_id AS teacherId, b.avatar, b.name AS teacherName," +
            " c.lesson_status AS lessonStatus,c.read_status AS readStatus,  c.question_status AS questionStatus,  c.score,c.comment, c.star ,c.created_time as createdTime FROM t_unit a  LEFT JOIN t_teacher b   ON a.teacher_id = b.id LEFT JOIN t_user_unit c ON c.unit_id=a.id   AND user_id =#{userid}  WHERE a.level_id = #{id} order by a.created_time asc")
    List<Map<String, Object>> queryByLevelAndUser(@Param("userid")String userid, @Param("id")String id);
}
